<?php
class Categorymanager_Model_Pagedecision implements Categorymanager_Model_Mainable{
    
    private $action_handler;
    
    private $get_status_lists;
    private $get_access_level_list;
    private $get_image_list;
    private $get_module_list;
    private $get_csrf_token;
    
    private $categorymanager_data_selectcurrentcategorydata;
    
    public function main(array $variables = null) {
        switch($variables['get']['page']){
            case "dodaj-kategorie":
                return $this->add_category($variables);
                break;
            case "wstaw-kategorie":
                return $this->insert_category($variables);
                break;
            case "edytuj-kategorie":
                return $this->edit_category($variables);
                break;
            case "aktualizuj-kategorie":
                return $this->update_category($variables);
                break;
            case "usun-kategorie":
                return $this->delete_category($variables);
                break;
            default:
                return $this->default_action($variables);
                break;
        }
    }
    
    private function delete_category(array $variables = null){
        $this->action_handler = new Categorymanager_Model_Deletecategory;
        return $this->action_handler->main($variables);
    }
    
    private function update_category(array $variables = null){
        //var_dump($variables);
        //die();
        $this->action_handler = new Categorymanager_Model_Updatecategory;
        return $this->action_handler->main($variables);
    }

    private function edit_category(array $variables = null){
        if(isset($variables['get']['name'])){
            $page = $this->get_other_data($variables);
            $this->categorymanager_data_selectcurrentcategorydata = new Categorymanager_Data_Selectcurrentcategorydata;
            $page['current_category_data'] = $this->categorymanager_data_selectcurrentcategorydata->main($variables);
            $page['template'] = WEB_ROOT_FOLDER."categorymanager/views/add.php";
            return $page;
        }
        else {
            return $this->default_action($variables);
        }
    }
    
    private function insert_category(array $variables = null){
        $this->action_handler = new Categorymanager_Model_Insertcategory;
        return $this->action_handler->main($variables);
    }
    
    private function add_category(array $variables = null){
        $page = $this->get_other_data($variables);
        $page['template'] = WEB_ROOT_FOLDER."categorymanager/views/add.php";
        return $page;
    }
    
    private function default_action(array $variables = null){
        unset($variables);
        $this->action_handler = new Categorymanager_Model_Categorymanager;
        return $this->action_handler->main($variables);
    }
    
    private function get_other_data(array $variables = null){
        $this->get_csrf_token = new Core_Controller_Csrftoken;
        $page['csrf_token'] = $this->get_csrf_token->main($variables);
        $this->get_access_level_list = new Privileges_Data_Getpriviligeslist;
        $page['access_levels'] = $this->get_access_level_list->main($variables);
        $this->get_status_lists = new Accountsstatus_Data_Getaccountsstatus;
        $page['statuses_name'] = $this->get_status_lists->main($variables);
        $this->get_image_list = new Modulemanager_Data_Selectimage;
        $page['images'] = $this->get_image_list->main($variables);
        $this->get_module_list = new Categorymanager_Data_Seelectmodulelist;
        $page['module_list'] = $this->get_module_list->main($variables);
        return $page;
    }

}
